package com.qqtech.qquan.community.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.community.model.CommunityYellow;
import com.qqtech.qquan.community.model.CommunityYellowQuery;
import com.qqtech.qquan.community.model.CommunityYellowVo;
import com.qqtech.qquan.community.service.CommunityYellowService;
import com.qqtech.web.context.BaseWebController;

@Controller
@RequestMapping(value = "/community/yellow")
public class CommunityYellowController extends BaseWebController<CommunityYellow, CommunityYellowQuery> {
	@Resource
	private CommunityYellowService communityYellowService;

	@Override
	protected BaseService<CommunityYellow> getBaseService() {
		return communityYellowService;
	}

	/**
	 * 分页
	 * 
	 * @param communityYellowQuery
	 * @return
	 */
	@RequestMapping(value = "/page")
	@ResponseBody
	public Result page(@RequestBody CommunityYellowQuery communityYellowQuery) {
		Result result = new Result();
		if (communityYellowQuery.getType() == null || communityYellowQuery.getType().intValue() == 0) {// 全部
			communityYellowQuery.setType(null);
		}
		Pageable pageKit = new PageKit(communityYellowQuery.getPage(), Integer.MAX_VALUE,
				new PageOrder(Direction.DESC, "id"));
		Page<CommunityYellowVo> page = communityYellowService.queryPageList(communityYellowQuery, pageKit);
		result.put("page", page);
		return result;
	}

	@RequestMapping(value = "/detail")
	@ResponseBody
	public Result detail(@RequestBody CommunityYellow communityYellow) {
		Result result = new Result();
		CommunityYellowVo detail = communityYellowService.getById(communityYellow.getId());
		result.put("detail", detail);
		return result;
	}

	/**
	 * 搜索
	 * 
	 * @param communityYellowQuery
	 * @return
	 */
	@RequestMapping(value = "/search")
	@ResponseBody
	public Result search(@RequestBody CommunityYellowQuery communityYellowQuery) {
		Result ret = new Result();
		List<CommunityYellowVo> lisYellow = communityYellowService.queryList(communityYellowQuery);
		ret.put("lisYellow", lisYellow);
		return ret;
	}

}
